#include <iostream>
#include <vector>
using namespace std;

class Solution {
public:
    vector<string> commonChars(vector<string>& words) {
        vector<string> result;
        if(!words.size()) return result;
        int hash[26] = {0};
        int hashOtherStr[26] = {0};
        // 对hash初始化
        for(int i = 0; i < words[0].size(); ++i){
            hash[words[0][i] - 'a']++;
        }
        for(int j = 1; j < words.size(); ++j){
            memset(hashOtherStr,0,26 * sizeof(int));
            for(int i = 0; i < words[j].size(); ++i){
                hashOtherStr[words[j][i] - 'a']++;
            }
            // 更新hash
            for(int k = 0; k < 26; ++k){
                hash[k] = min(hash[k],hashOtherStr[k]);
            }
        }
        for(int i = 0; i < 26; ++i){
            while(hash[i] != 0){
                string s(1,'a'+i);
                result.push_back(s);
                --hash[i];
            }
        }
        return result;
    }
};